package com.future;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Description: 1114. �����ӡ
 *
 * @Author: future
 * @Date:2022/5/10:23:16
 */
public class Solution_1114 {

    public static void main(String[] args) {
        test1();
    }

    private static void test1() {

    }


    class Foo {

        public Foo() {

        }

        private AtomicInteger first = new AtomicInteger(0);
        private AtomicInteger second = new AtomicInteger(0);

        public void first(Runnable printFirst) throws InterruptedException {

            // printFirst.run() outputs "first". Do not change or remove this line.
            printFirst.run();
            first.getAndIncrement();
        }

        public void second(Runnable printSecond) throws InterruptedException {
            while (first.get() != 1) {
                continue;
            }
            // printSecond.run() outputs "second". Do not change or remove this line.
            printSecond.run();
            second.getAndIncrement();
        }

        public void third(Runnable printThird) throws InterruptedException {
            while (second.get() != 1) {
                continue;
            }
            // printThird.run() outputs "third". Do not change or remove this line.
            printThird.run();
        }

        private AtomicInteger flag = new AtomicInteger(0);

        // ============================������==============
        public void first_v2(Runnable printFirst) throws InterruptedException {

            // printFirst.run() outputs "first". Do not change or remove this line.
            printFirst.run();
            flag.getAndIncrement();
        }

        public void second_v2(Runnable printSecond) throws InterruptedException {
            while (flag.get() != 1) {
                continue;
            }
            // printSecond.run() outputs "second". Do not change or remove this line.
            printSecond.run();
            flag.getAndIncrement();
        }

        public void third_v2(Runnable printThird) throws InterruptedException {
            while (second.get() != 2) {
                continue;
            }
            // printThird.run() outputs "third". Do not change or remove this line.
            printThird.run();
        }
    }
}
